/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package elementsDefense.gui;

import com.jme3.asset.AssetManager;
import com.jme3.input.controls.ActionListener;
import com.jme3.material.Material;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.shape.Quad;

/**
 *
 * @author Ricardo
 */
public class Button {
    String name;
    int x,y;
    int width,height;
    int x_width,y_height;

    public Button(int x, int y, int width, int height, String name, AssetManager assetManager, Node guiNode) {
        this.name = name;
        this.x = x;
        this.y = y;
        this.width = width;
        this.height = height;
        this.x_width = x+width;
        this.y_height = y-height;
        
        
        Geometry openFlow = new Geometry("Button "+name, new Quad(width, height));
        Material mat_openFlow = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        mat_openFlow.setTexture("ColorMap", assetManager.loadTexture("Interface/"+name+".jpg"));
        openFlow.setMaterial(mat_openFlow);
        openFlow.setLocalTranslation(x, y-height, 0);
        guiNode.attachChild(openFlow);
    }
    
    public boolean contains(int x, int y){
        System.out.printf("%d<%d<%d %d<%d<%d \n", this.x, x, this.x_width, this.y, y, this.y_height);
        return x>this.x && x<this.x_width && y<this.y && y>this.y_height ;
    }
    
    public void click(){
        HUD.actionListener.onAction(name, true, 0);
    }
}
